package com.zhiyou100.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.zhiyou100.model.Result;
import com.zhiyou100.model.User;
import com.zhiyou100.service.UserService;

@Controller
@RequestMapping("/user/")
public class UserController {
	
	@Autowired  //自动装配
	private UserService userService;
	public UserService getUserService() {
		return userService;
	}
	public void setUserService(UserService userService) {
		this.userService = userService;
	}


	@RequestMapping(value="reg.do",method={RequestMethod.POST})
	public String reg(User user){
		Result result = userService.insertUser(user);
		System.out.println(result);
		return "success";
	}
	@RequestMapping(value="select.do",method= {RequestMethod.POST})
	public String select() {
		  Result result=userService.selectAll();
		System.out.println(result);
		
		return "select";
		
	}
	
	@RequestMapping(value="delete.do",method= {RequestMethod.POST})
	public String delete(int id) {
		  Result result=userService.delete(id);
		System.out.println(result);
		
		return "delete";
		
	}
	
	@RequestMapping(value="update.do",method= {RequestMethod.POST})
	public String update(User username) {
		  Result result=userService.update(username);
		System.out.println(result);
		
		return "update";
		
	}
	
	
}
